package com.guigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.guigu.constant.MessageConstant;
import com.guigu.entity.PageResult;
import com.guigu.entity.QueryPageBean;
import com.guigu.entity.Result;
import com.guigu.pojo.Member;
import com.guigu.pojo.Order;
import com.guigu.pojo.Setmeal;
import com.guigu.service.OrderService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * @author Kc
 * @date 2021-04-21
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Reference
    private OrderService orderService;

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult=orderService.queryAllOrder(
                queryPageBean.getCurrentPage(),
                queryPageBean.getPageSize(),
                queryPageBean.getQueryString(),
                queryPageBean.getQueryStatus()
        );
        return pageResult;
    }
    @RequestMapping("/updateById")
    public Result updateById(Integer id){
        System.out.println(id);
        boolean b = orderService.updateById(id);
        if(b){
            return new Result(true, MessageConstant.ORDER_SUCCESS);
        }
        return new Result(false,MessageConstant.ORDER_FULL);
    }

    @RequestMapping("/updateById2")
    public Result updateById2(Integer id){
        boolean b = orderService.updateById2(id);
        if(b){
            return new Result(true, MessageConstant.ORDER_SUCCESS);
        }
        return new Result(false,MessageConstant.ORDER_FULL);
    }
    @RequestMapping("/findAll")
    public Result queryAll(){
        List<Member> members = orderService.queryAllMember();
        Result result=new Result(true,MessageConstant.QUERY_SETMEALLIST_SUCCESS);
        result.setData(members);
        return result;
    }
    @RequestMapping("/findAll2")
    public Result queryAll2(){
        List<Setmeal> setmeals = orderService.queryAllSetmeal();
        Result result=new Result(true,MessageConstant.QUERY_SETMEALLIST_SUCCESS);
        result.setData(setmeals);
        return result;
    }

    @RequestMapping("/add")
    public Result add(@RequestBody Order order){
        System.out.println("order = " + order);
        boolean b = orderService.add(order);
        if(b){
            return new Result(true, MessageConstant.ORDER_SUCCESS);
        }
        return new Result(false,MessageConstant.ORDER_FULL);
    }
}
